package com.isoft.demo01.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.demo01.entity.Game;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
@Mapper
public interface GameDao extends BaseMapper<Game> {
    @Select("<script>"+
            "select * from tb_game " +
            "        <where> " +
            "            <if test=\"null != gameid\"> " +
            "                and gameid=#{gameid} " +
            "            </if> " +
            "            <if test=\"null != gamename\"> " +
            "                <bind gamename=\"gamenameKey\" value=\"'%'+gamename+'%'\"/> " +
            "                and gamename like #{gamename} " +
            "            </if> " +
            "        </where> " +
            "limit ${offset} , ${size}"
            +"</script>")
    public List<Game> findLimit(@Param("gameid") Integer gameid , @Param("gamename")String gamename , @Param("offset")Integer offset , @Param("size")Integer size) ;

    @Select("<script>"+
            "select count(*) from tb_game " +
            "        <where> " +
            "            <if test=\"null != gameid\"> " +
            "                and gameid=#{gameid} " +
            "            </if> " +
            "            <if test=\"null != gamename\"> " +
            "                <bind gamename=\"gamenameKey\" value=\"'%'+gamename+'%'\"/> " +
            "                and gamename like #{gamename} " +
            "            </if> " +
            "        </where>"
            +"</script>")
    public int getCount(@Param("gameid") Integer gameid , @Param("gamename")String gamename) ;
    @Select("select * from tb_game inner join tb_gametype  on tb_game.typeid=tb_gametype.typeid where tb_gametype.typeid=#{typeid}")
    List<Game> findmenu(Integer typeid);

}
